package com.clh.service.impl;

import java.util.List;

import com.clh.common.PageInfo;
import com.clh.dao.FamilyDao;
import com.clh.dao.impl.FamilyDaoImpl;
import com.clh.entity.Family;
import com.clh.service.FamilyService;

/**
 * @Description: TODO(用一句话描述该文件做什么)
 * @author 邱宏宇 
 * @date 2022年5月26日 下午2:47:20
 * @version V1.0
 */
public class FamilyServiceImpl implements FamilyService{
	private FamilyDao familyDao = new FamilyDaoImpl();

	@Override
	public PageInfo<Family> getFamilyByPage(Family family, int pageNum, int pageSize) {
		//模糊查询加工
		StringBuilder familyName = new StringBuilder();
		if(family.getFamilyName()!=null && !"".equals(family.getFamilyName())) {
			familyName.append("%").append(family.getFamilyName()).append("%");
			family.setFamilyName(familyName.toString());
		}
		StringBuilder familyCard = new StringBuilder();
		if(family.getFamilyCard()!=null && !"".equals(family.getFamilyCard())) {
			familyCard.append("%").append(family.getFamilyName()).append("%");
			family.setFamilyName(familyCard.toString());
		}
		//调用dao获取分页结果 获取总条数
		List<Family> list = familyDao.findFamilyByPage(family, pageNum, pageSize);
		int total = familyDao.countByCondition(family);
		
		//封装pageInfo
		PageInfo<Family> pageInfo = new PageInfo<Family>(list, pageNum, pageSize, total);
		return pageInfo;
	}

	@Override
	public boolean addFamily(Family family) {
		
		return familyDao.addFamily(family);
	}

	@Override
	public boolean delFamily(String familyCard) {
		return familyDao.delFamily(familyCard);
	}

	@Override
	public boolean modifyFamily(Family family) {
		
		return familyDao.modifyFamily(family);
	}

	@Override
	public Family getFamilyByFamilyCard(String familyCard) {
		
		return familyDao.getByFamilyCard(familyCard);
	}

	@Override
	public List<Family> getListByRoomNo(String roomNo) {
		
		return familyDao.getListByRoomNo(roomNo);
	} 

	

	
}
